<template>
  <div>
    <a-form :form="form" class="forms pt48" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
      <a-form-item label="密码类型">
        <a-select
          v-decorator="[
            'passwordType',
            {
              initialValue: 0,
              rules: [
                {
                  required: true,
                  message: '密码类型不能为空'
                }
              ]
            }
          ]"
          placeholder="请选择"
        >
          <a-select-option :value="item.id" v-for="item in typeArr" :key="item.id">{{ item.name }}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="申报密码" v-if="form.getFieldValue('passwordType') == 0">
        <a-input
          placeholder="请输入密码"
          :maxLength="50"
          v-decorator="['declarePassword', { rules: [{ required: true, message: '申报密码不能为空' }] }]"
        />
      </a-form-item>
      <a-form-item label="实名账号" v-if="form.getFieldValue('passwordType') == 2">
        <a-input
          placeholder="请输入账号"
          :maxLength="50"
          v-decorator="['realNameAccount', { rules: [{ required: true, message: '实名账号不能为空' }] }]"
        />
      </a-form-item>
      <a-form-item label="实名密码" v-if="form.getFieldValue('passwordType') == 2">
        <a-input
          placeholder="请输入密码"
          :maxLength="50"
          v-decorator="['realNamePassword', { rules: [{ required: true, message: '实名密码不能为空' }] }]"
        />
      </a-form-item>
      <a-form-item>
        <a-button class="mr12" style="margin-left: 100px" @click="$emit('upData', 0)">上一步</a-button>
        <a-button type="primary" @click="handleOk" :loading="confirmLoading">确认</a-button>
      </a-form-item>
    </a-form>
    <popUp ref="popVal"></popUp>
  </div>
</template>

<script>
import popUp from "../../component/popUp";
import { postDeclarationSubmit } from "./api";
export default {
  data() {
    return {
      confirmLoading: false,
      form: this.$form.createForm(this, {}),
      typeArr: [
        { id: 0, name: "申报密码" },
        { id: 2, name: "实名密码" }
      ]
    };
  },
  components: {
    popUp
  },
  created() {
    setTimeout(() => {
      this.form.setFieldsValue({
        passwordType: 0
      });
    });
  },
  methods: {
    async onPostDeclarationSubmit(v) {
      try {
        this.confirmLoading = true;
        const data = await postDeclarationSubmit(v);
        this.confirmLoading = false;
        // this.$refs.popVal.showModal(data,'已提交报送')
        // this.$notification.success({ message: "操作成功" });
        this.$emit("upData", 2);
        this.$emit("upDatadata", data);
      } catch (err) {
        console.log("error log --> ", err);
        this.confirmLoading = false;
      }
    },
    handleOk() {
      this.form.validateFields((err, values) => {
        if (!err) {
          const companyAuthId = sessionStorage.getItem("taxCalculate/authorityId");
          const period = sessionStorage.getItem("taxCalculate/period");
          const tabType = sessionStorage.getItem("taxCalculate/tabType");
          const submitType = sessionStorage.getItem("taxCalculate/submitType");
          const reportIdArr = sessionStorage.getItem("taxCalculate/reportIdArr");
          const json = {
            companyAuthId,
            isAll: true,
            period,
            tabType,
            submitType,
            ...values
          };
          const arr = reportIdArr ? JSON.parse(reportIdArr) : [];
          if (arr.length > 0) {
            json.recordIds = arr;
            json.isAll = false;
          }
          console.log(json);
          this.onPostDeclarationSubmit(json);
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.forms {
  width: 400px;
  margin: 0 auto;
  ::v-deep .ant-form-item-label > label {
    font-weight: normal !important;
    color: #55565d !important;
  }
  ::v-deep #remark {
    height: 80px !important;
  }
}
</style>
